package leetcode;

import org.junit.Test;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author Liangyaoyun
 */
public class MyStack {
    Queue<Integer>inQueue;
    Queue<Integer>outQueue;
    public MyStack() {
        inQueue=new LinkedList<>();
        outQueue=new LinkedList<>();
    }

    public void push(int x) {
        //将x存入辅助队列中
        outQueue.offer(x);
        //判断主队列
        while(!inQueue.isEmpty()){
            //如果主队列有剩余元素将它加入到辅助队列中
            outQueue.offer(inQueue.poll());
        }
        //将主队列和辅助队列交换
        Queue<Integer>t=inQueue;
        inQueue=outQueue;
        outQueue=t;
    }
    public int pop() {

        return inQueue.poll();
    }

    public int top() {
        return inQueue.peek();

    }

    public boolean empty() {
        return inQueue.isEmpty();
    }
}
